<?php


abstract class BaseCita extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $fecha;


	
	protected $turno_id;


	
	protected $especialista_id;


	
	protected $solicitante_id;


	
	protected $tipo_cita;


	
	protected $motivo;


	
	protected $bloque_id;

	
	protected $aTurno;

	
	protected $aAteneausuarioRelatedByEspecialistaId;

	
	protected $aAteneausuarioRelatedBySolicitanteId;

	
	protected $aBloque;

	
	protected $collConsultas;

	
	protected $lastConsultaCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getFecha($format = 'Y-m-d')
	{

		if ($this->fecha === null || $this->fecha === '') {
			return null;
		} elseif (!is_int($this->fecha)) {
						$ts = strtotime($this->fecha);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [fecha] as date/time value: " . var_export($this->fecha, true));
			}
		} else {
			$ts = $this->fecha;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function getTurnoId()
	{

		return $this->turno_id;
	}

	
	public function getEspecialistaId()
	{

		return $this->especialista_id;
	}

	
	public function getSolicitanteId()
	{

		return $this->solicitante_id;
	}

	
	public function getTipoCita()
	{

		return $this->tipo_cita;
	}

	
	public function getMotivo()
	{

		return $this->motivo;
	}

	
	public function getBloqueId()
	{

		return $this->bloque_id;
	}

	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = CitaPeer::ID;
		}

	} 
	
	public function setFecha($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [fecha] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->fecha !== $ts) {
			$this->fecha = $ts;
			$this->modifiedColumns[] = CitaPeer::FECHA;
		}

	} 
	
	public function setTurnoId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->turno_id !== $v) {
			$this->turno_id = $v;
			$this->modifiedColumns[] = CitaPeer::TURNO_ID;
		}

		if ($this->aTurno !== null && $this->aTurno->getId() !== $v) {
			$this->aTurno = null;
		}

	} 
	
	public function setEspecialistaId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->especialista_id !== $v) {
			$this->especialista_id = $v;
			$this->modifiedColumns[] = CitaPeer::ESPECIALISTA_ID;
		}

		if ($this->aAteneausuarioRelatedByEspecialistaId !== null && $this->aAteneausuarioRelatedByEspecialistaId->getId() !== $v) {
			$this->aAteneausuarioRelatedByEspecialistaId = null;
		}

	} 
	
	public function setSolicitanteId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->solicitante_id !== $v) {
			$this->solicitante_id = $v;
			$this->modifiedColumns[] = CitaPeer::SOLICITANTE_ID;
		}

		if ($this->aAteneausuarioRelatedBySolicitanteId !== null && $this->aAteneausuarioRelatedBySolicitanteId->getId() !== $v) {
			$this->aAteneausuarioRelatedBySolicitanteId = null;
		}

	} 
	
	public function setTipoCita($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->tipo_cita !== $v) {
			$this->tipo_cita = $v;
			$this->modifiedColumns[] = CitaPeer::TIPO_CITA;
		}

	} 
	
	public function setMotivo($v)
	{

						if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->motivo !== $v) {
			$this->motivo = $v;
			$this->modifiedColumns[] = CitaPeer::MOTIVO;
		}

	} 
	
	public function setBloqueId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->bloque_id !== $v) {
			$this->bloque_id = $v;
			$this->modifiedColumns[] = CitaPeer::BLOQUE_ID;
		}

		if ($this->aBloque !== null && $this->aBloque->getId() !== $v) {
			$this->aBloque = null;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->fecha = $rs->getDate($startcol + 1, null);

			$this->turno_id = $rs->getInt($startcol + 2);

			$this->especialista_id = $rs->getInt($startcol + 3);

			$this->solicitante_id = $rs->getInt($startcol + 4);

			$this->tipo_cita = $rs->getString($startcol + 5);

			$this->motivo = $rs->getString($startcol + 6);

			$this->bloque_id = $rs->getInt($startcol + 7);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 8; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Cita object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(CitaPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			CitaPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(CitaPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


												
			if ($this->aTurno !== null) {
				if ($this->aTurno->isModified()) {
					$affectedRows += $this->aTurno->save($con);
				}
				$this->setTurno($this->aTurno);
			}

			if ($this->aAteneausuarioRelatedByEspecialistaId !== null) {
				if ($this->aAteneausuarioRelatedByEspecialistaId->isModified()) {
					$affectedRows += $this->aAteneausuarioRelatedByEspecialistaId->save($con);
				}
				$this->setAteneausuarioRelatedByEspecialistaId($this->aAteneausuarioRelatedByEspecialistaId);
			}

			if ($this->aAteneausuarioRelatedBySolicitanteId !== null) {
				if ($this->aAteneausuarioRelatedBySolicitanteId->isModified()) {
					$affectedRows += $this->aAteneausuarioRelatedBySolicitanteId->save($con);
				}
				$this->setAteneausuarioRelatedBySolicitanteId($this->aAteneausuarioRelatedBySolicitanteId);
			}

			if ($this->aBloque !== null) {
				if ($this->aBloque->isModified()) {
					$affectedRows += $this->aBloque->save($con);
				}
				$this->setBloque($this->aBloque);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = CitaPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += CitaPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			if ($this->collConsultas !== null) {
				foreach($this->collConsultas as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->aTurno !== null) {
				if (!$this->aTurno->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aTurno->getValidationFailures());
				}
			}

			if ($this->aAteneausuarioRelatedByEspecialistaId !== null) {
				if (!$this->aAteneausuarioRelatedByEspecialistaId->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aAteneausuarioRelatedByEspecialistaId->getValidationFailures());
				}
			}

			if ($this->aAteneausuarioRelatedBySolicitanteId !== null) {
				if (!$this->aAteneausuarioRelatedBySolicitanteId->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aAteneausuarioRelatedBySolicitanteId->getValidationFailures());
				}
			}

			if ($this->aBloque !== null) {
				if (!$this->aBloque->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aBloque->getValidationFailures());
				}
			}


			if (($retval = CitaPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collConsultas !== null) {
					foreach($this->collConsultas as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = CitaPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getFecha();
				break;
			case 2:
				return $this->getTurnoId();
				break;
			case 3:
				return $this->getEspecialistaId();
				break;
			case 4:
				return $this->getSolicitanteId();
				break;
			case 5:
				return $this->getTipoCita();
				break;
			case 6:
				return $this->getMotivo();
				break;
			case 7:
				return $this->getBloqueId();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = CitaPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getFecha(),
			$keys[2] => $this->getTurnoId(),
			$keys[3] => $this->getEspecialistaId(),
			$keys[4] => $this->getSolicitanteId(),
			$keys[5] => $this->getTipoCita(),
			$keys[6] => $this->getMotivo(),
			$keys[7] => $this->getBloqueId(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = CitaPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setFecha($value);
				break;
			case 2:
				$this->setTurnoId($value);
				break;
			case 3:
				$this->setEspecialistaId($value);
				break;
			case 4:
				$this->setSolicitanteId($value);
				break;
			case 5:
				$this->setTipoCita($value);
				break;
			case 6:
				$this->setMotivo($value);
				break;
			case 7:
				$this->setBloqueId($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = CitaPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setFecha($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setTurnoId($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setEspecialistaId($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setSolicitanteId($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setTipoCita($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setMotivo($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setBloqueId($arr[$keys[7]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(CitaPeer::DATABASE_NAME);

		if ($this->isColumnModified(CitaPeer::ID)) $criteria->add(CitaPeer::ID, $this->id);
		if ($this->isColumnModified(CitaPeer::FECHA)) $criteria->add(CitaPeer::FECHA, $this->fecha);
		if ($this->isColumnModified(CitaPeer::TURNO_ID)) $criteria->add(CitaPeer::TURNO_ID, $this->turno_id);
		if ($this->isColumnModified(CitaPeer::ESPECIALISTA_ID)) $criteria->add(CitaPeer::ESPECIALISTA_ID, $this->especialista_id);
		if ($this->isColumnModified(CitaPeer::SOLICITANTE_ID)) $criteria->add(CitaPeer::SOLICITANTE_ID, $this->solicitante_id);
		if ($this->isColumnModified(CitaPeer::TIPO_CITA)) $criteria->add(CitaPeer::TIPO_CITA, $this->tipo_cita);
		if ($this->isColumnModified(CitaPeer::MOTIVO)) $criteria->add(CitaPeer::MOTIVO, $this->motivo);
		if ($this->isColumnModified(CitaPeer::BLOQUE_ID)) $criteria->add(CitaPeer::BLOQUE_ID, $this->bloque_id);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(CitaPeer::DATABASE_NAME);

		$criteria->add(CitaPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setFecha($this->fecha);

		$copyObj->setTurnoId($this->turno_id);

		$copyObj->setEspecialistaId($this->especialista_id);

		$copyObj->setSolicitanteId($this->solicitante_id);

		$copyObj->setTipoCita($this->tipo_cita);

		$copyObj->setMotivo($this->motivo);

		$copyObj->setBloqueId($this->bloque_id);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach($this->getConsultas() as $relObj) {
				$copyObj->addConsulta($relObj->copy($deepCopy));
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new CitaPeer();
		}
		return self::$peer;
	}

	
	public function setTurno($v)
	{


		if ($v === null) {
			$this->setTurnoId(NULL);
		} else {
			$this->setTurnoId($v->getId());
		}


		$this->aTurno = $v;
	}


	
	public function getTurno($con = null)
	{
				include_once 'lib/model/om/BaseTurnoPeer.php';

		if ($this->aTurno === null && ($this->turno_id !== null)) {

			$this->aTurno = TurnoPeer::retrieveByPK($this->turno_id, $con);

			
		}
		return $this->aTurno;
	}

	
	public function setAteneausuarioRelatedByEspecialistaId($v)
	{


		if ($v === null) {
			$this->setEspecialistaId(NULL);
		} else {
			$this->setEspecialistaId($v->getId());
		}


		$this->aAteneausuarioRelatedByEspecialistaId = $v;
	}


	
	public function getAteneausuarioRelatedByEspecialistaId($con = null)
	{
				include_once 'lib/model/om/BaseAteneausuarioPeer.php';

		if ($this->aAteneausuarioRelatedByEspecialistaId === null && ($this->especialista_id !== null)) {

			$this->aAteneausuarioRelatedByEspecialistaId = AteneausuarioPeer::retrieveByPK($this->especialista_id, $con);

			
		}
		return $this->aAteneausuarioRelatedByEspecialistaId;
	}

	
	public function setAteneausuarioRelatedBySolicitanteId($v)
	{


		if ($v === null) {
			$this->setSolicitanteId(NULL);
		} else {
			$this->setSolicitanteId($v->getId());
		}


		$this->aAteneausuarioRelatedBySolicitanteId = $v;
	}


	
	public function getAteneausuarioRelatedBySolicitanteId($con = null)
	{
				include_once 'lib/model/om/BaseAteneausuarioPeer.php';

		if ($this->aAteneausuarioRelatedBySolicitanteId === null && ($this->solicitante_id !== null)) {

			$this->aAteneausuarioRelatedBySolicitanteId = AteneausuarioPeer::retrieveByPK($this->solicitante_id, $con);

			
		}
		return $this->aAteneausuarioRelatedBySolicitanteId;
	}

	
	public function setBloque($v)
	{


		if ($v === null) {
			$this->setBloqueId(NULL);
		} else {
			$this->setBloqueId($v->getId());
		}


		$this->aBloque = $v;
	}


	
	public function getBloque($con = null)
	{
				include_once 'lib/model/om/BaseBloquePeer.php';

		if ($this->aBloque === null && ($this->bloque_id !== null)) {

			$this->aBloque = BloquePeer::retrieveByPK($this->bloque_id, $con);

			
		}
		return $this->aBloque;
	}

	
	public function initConsultas()
	{
		if ($this->collConsultas === null) {
			$this->collConsultas = array();
		}
	}

	
	public function getConsultas($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseConsultaPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collConsultas === null) {
			if ($this->isNew()) {
			   $this->collConsultas = array();
			} else {

				$criteria->add(ConsultaPeer::CITA_ID, $this->getId());

				ConsultaPeer::addSelectColumns($criteria);
				$this->collConsultas = ConsultaPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(ConsultaPeer::CITA_ID, $this->getId());

				ConsultaPeer::addSelectColumns($criteria);
				if (!isset($this->lastConsultaCriteria) || !$this->lastConsultaCriteria->equals($criteria)) {
					$this->collConsultas = ConsultaPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastConsultaCriteria = $criteria;
		return $this->collConsultas;
	}

	
	public function countConsultas($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseConsultaPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(ConsultaPeer::CITA_ID, $this->getId());

		return ConsultaPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addConsulta(Consulta $l)
	{
		$this->collConsultas[] = $l;
		$l->setCita($this);
	}


	
	public function getConsultasJoinDiagnostico($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseConsultaPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collConsultas === null) {
			if ($this->isNew()) {
				$this->collConsultas = array();
			} else {

				$criteria->add(ConsultaPeer::CITA_ID, $this->getId());

				$this->collConsultas = ConsultaPeer::doSelectJoinDiagnostico($criteria, $con);
			}
		} else {
									
			$criteria->add(ConsultaPeer::CITA_ID, $this->getId());

			if (!isset($this->lastConsultaCriteria) || !$this->lastConsultaCriteria->equals($criteria)) {
				$this->collConsultas = ConsultaPeer::doSelectJoinDiagnostico($criteria, $con);
			}
		}
		$this->lastConsultaCriteria = $criteria;

		return $this->collConsultas;
	}


	
	public function getConsultasJoinDatoEstudiante($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseConsultaPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collConsultas === null) {
			if ($this->isNew()) {
				$this->collConsultas = array();
			} else {

				$criteria->add(ConsultaPeer::CITA_ID, $this->getId());

				$this->collConsultas = ConsultaPeer::doSelectJoinDatoEstudiante($criteria, $con);
			}
		} else {
									
			$criteria->add(ConsultaPeer::CITA_ID, $this->getId());

			if (!isset($this->lastConsultaCriteria) || !$this->lastConsultaCriteria->equals($criteria)) {
				$this->collConsultas = ConsultaPeer::doSelectJoinDatoEstudiante($criteria, $con);
			}
		}
		$this->lastConsultaCriteria = $criteria;

		return $this->collConsultas;
	}


	
	public function getConsultasJoinAteneausuario($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseConsultaPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collConsultas === null) {
			if ($this->isNew()) {
				$this->collConsultas = array();
			} else {

				$criteria->add(ConsultaPeer::CITA_ID, $this->getId());

				$this->collConsultas = ConsultaPeer::doSelectJoinAteneausuario($criteria, $con);
			}
		} else {
									
			$criteria->add(ConsultaPeer::CITA_ID, $this->getId());

			if (!isset($this->lastConsultaCriteria) || !$this->lastConsultaCriteria->equals($criteria)) {
				$this->collConsultas = ConsultaPeer::doSelectJoinAteneausuario($criteria, $con);
			}
		}
		$this->lastConsultaCriteria = $criteria;

		return $this->collConsultas;
	}


	
	public function getConsultasJoinMotivoConsulta($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseConsultaPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collConsultas === null) {
			if ($this->isNew()) {
				$this->collConsultas = array();
			} else {

				$criteria->add(ConsultaPeer::CITA_ID, $this->getId());

				$this->collConsultas = ConsultaPeer::doSelectJoinMotivoConsulta($criteria, $con);
			}
		} else {
									
			$criteria->add(ConsultaPeer::CITA_ID, $this->getId());

			if (!isset($this->lastConsultaCriteria) || !$this->lastConsultaCriteria->equals($criteria)) {
				$this->collConsultas = ConsultaPeer::doSelectJoinMotivoConsulta($criteria, $con);
			}
		}
		$this->lastConsultaCriteria = $criteria;

		return $this->collConsultas;
	}


	
	public function getConsultasJoinTrastorno($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseConsultaPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collConsultas === null) {
			if ($this->isNew()) {
				$this->collConsultas = array();
			} else {

				$criteria->add(ConsultaPeer::CITA_ID, $this->getId());

				$this->collConsultas = ConsultaPeer::doSelectJoinTrastorno($criteria, $con);
			}
		} else {
									
			$criteria->add(ConsultaPeer::CITA_ID, $this->getId());

			if (!isset($this->lastConsultaCriteria) || !$this->lastConsultaCriteria->equals($criteria)) {
				$this->collConsultas = ConsultaPeer::doSelectJoinTrastorno($criteria, $con);
			}
		}
		$this->lastConsultaCriteria = $criteria;

		return $this->collConsultas;
	}


	
	public function getConsultasJoinHistoriaPsicologica($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseConsultaPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collConsultas === null) {
			if ($this->isNew()) {
				$this->collConsultas = array();
			} else {

				$criteria->add(ConsultaPeer::CITA_ID, $this->getId());

				$this->collConsultas = ConsultaPeer::doSelectJoinHistoriaPsicologica($criteria, $con);
			}
		} else {
									
			$criteria->add(ConsultaPeer::CITA_ID, $this->getId());

			if (!isset($this->lastConsultaCriteria) || !$this->lastConsultaCriteria->equals($criteria)) {
				$this->collConsultas = ConsultaPeer::doSelectJoinHistoriaPsicologica($criteria, $con);
			}
		}
		$this->lastConsultaCriteria = $criteria;

		return $this->collConsultas;
	}

} 